<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<view class="cu-bar bg-white ">
			<view class="action">
				<u-icon name="/static/common/img/invcode.png" size="80"></u-icon>
				<text class="cuIcon-titles text-green text-bold">发货单选择</text> 
			</view>
		</view>
		<u-form class="form bg-white" :model="model"  ref="uForm" label-position="left">
			<u-form-item label="车牌号:" prop="carNo" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入车牌号" v-model="model.carNo" type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="计划发货日期" prop="time" label-width="200" :label-style="{'font-weight':'bold'}">
			    <u-input placeholder="请输入日期" v-model="model.planDate" type="select" :select-open="pickerTime" @click="pickerTime = true"></u-input>
			</u-form-item>
			<u-picker mode="time" v-model="pickerTime" @confirm="timeConfirm"></u-picker>
			<u-form-item label="司机:" prop="cdriver" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入司机" v-model="model.cdriver" type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="司机电话:" prop="driverPhone" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入司机电话" v-model="model.driverPhone" type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="运输单位:" prop="testCarVen" label-width="200" :label-style="{'font-weight':'bold'}">
				<js-select v-model="model.carVenCode" :items="carVenSelectList" placeholder="请选择运输单位" :tree="true"
					:label-value="model.carVenName" @label-input="model.carVenName = $event"></js-select>
			</u-form-item>
			<u-form-item label="备注:" prop="remarks" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入备注" v-model="model.remarks" type="text" di maxlength="64"></u-input>
			</u-form-item>
		</u-form>
		<view class="form-footer b-btns">
			<view class="footer">
				<u-button class="btn" type="primary" @click="submit">保存</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model:{
					id:'',
					carNo:'',
					planDate:'',
					cdriver:'',
					driverPhone:'',
					carVenCode:'',
					carVenName:'',
					remarks:'',
				},
				carVenSelectList: [],
				pickerTime: false,//控制日期显示
			}
		},
		onLoad(params){
			
		},
		onShow() {
		},
		onReady() {
			// 运输单位数据
			this.$u.api.carVen.treeData().then(res => {
				this.carVenSelectList = res;
			});
		},
		methods: {
			timeConfirm(e){
				this.model.planDate = e.year + '-' + e.month + '-' + e.day;
			},
			submit(data, callback) {
				if(this.model.carNo == null || this.model.carNo == ''){
					this.$refs.jsError.showError('','请正确填入车牌号！','error');
					return;
				}else if(this.model.planDate == null || this.model.planDate == ''){
					this.$refs.jsError.showError('','请正确选择计划发货日期！','error');
					return;
				}else if(this.model.carVenCode == null || this.model.carVenCode == ''){
					this.$refs.jsError.showError('','请正确选择运输单位！','error');
					return;
				}else{
					var data = {
						mfCarplanFhH: JSON.stringify(this.model),
						useStatus: 1
					};
					this.$u.api.mffh.save(data).then(res => {
						if(res.result == 'true'){
							this.$u.toast(res.message);
							this.model.carNo = '';
							this.model.planDate = '';
							this.model.cdriver = '';
							this.model.driverPhone = '';
							this.model.carVenCode = '';
							this.model.carVenName = '';
							this.model.remarks = '';
						}else{
							this.$refs.jsError.showError('',res.message,'error');
						}
					});
				}
			},
		}
	}
</script>
<style>
.footer {
	position: fixed;
	left: 0;
	bottom: 20px;
	width: 100%;
	
}
</style>